package com.hi.hiparty.entity.typehandler;

import java.sql.SQLException;

import org.apache.commons.lang.StringUtils;

import com.ibatis.sqlmap.client.extensions.ParameterSetter;
import com.ibatis.sqlmap.client.extensions.ResultGetter;
import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;

public class TagsHandlerCallback implements TypeHandlerCallback {
	private static final String SPLIT_FLAG = ";";  
	@Override
	public Object getResult(ResultGetter arg0) throws SQLException {
        String tags = arg0.getString(); 		
        if(!StringUtils.isBlank(tags)){
        	return tags.split(SPLIT_FLAG);
        }else{
        	return null;
        }
	}

	@Override
	public void setParameter(ParameterSetter arg0, Object arg1)
			throws SQLException {
		String[] tags =(String[])arg1;
		StringBuilder sb = new StringBuilder();
		if(null==tags ||0 == tags.length){
			
		}else if(tags.length>=1){
			for(String tag:tags){
				sb.append(tag).append(SPLIT_FLAG);
			}
			sb.replace(sb.length()-1, sb.length(), "");
			arg0.setString(sb.toString());
		}
	}

	@Override
	public Object valueOf(String arg0) {
		return null;
	}

}
